import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../views/Valid/Login.vue'
import Register from '../views/Valid/Register.vue'
import Home from '../views/Home/Home.vue'
import HomeGoods from '../views/Home/Nav/HomeNav2Goods.vue'
import HomePurchase from '../views/Home/Nav/HomeNav3Purchase.vue'
import HomeKnowledge from '../views/Home/Nav/HomeNav4Knowledge.vue'
import KnowledgeDetail from '../views/Home/Detail/KnowledgeDetail.vue'
import ShopCart from '../views/Home/Nav/HomeNav6ShopCart.vue'
import Payment from '../views/Valid/Payment.vue'
import Details from '../views/Home/Detail/GoodDetails.vue'
import purchaseDetails from '../views/Home/Detail/purchaseDetails.vue'
import User from '../views/User/User.vue'
import UserInfo from '../views/User/UserInfo.vue'
import UserFinance from '../views/User/UserFinance.vue'
import UserAddress from '../views/User/UserAddress.vue'
import UserPassword from '../views/User/UserPassword.vue'
import PublishNav from '../components/message/PublishNav.vue'
import PublishGoods from '../views/User/publish/PublishGoods.vue'
import PublishNeeds from '../views/User/publish/PublishNeeds.vue'
import PublishKnowledges from '../views/User/expert/expertPublishKnowledges.vue'
import PublishedGoods from '../views/User/publish/PublishedGoods.vue'
import PublishedNeeds from '../views/User/publish/PublishedNeeds.vue'
import PublishedGoodsAdmin from '../views/User/publish/PublishedGoodsAdmin.vue'
import PublishedNeedsAdmin from '../views/User/publish/PublishedNeedsAdmin.vue'
import PublishedKnowledges from '../views/User/expert/expertPublishedKnowledges.vue'
import UserBuy from '../views/User/UserBuy.vue'
import UserSell from '../views/User/UserSell.vue'
import expertQuestion from '../views/User/expert/expertQuestion.vue'
import expertAppoint from '../views/User/expert/expertAppoint.vue'
import expertInfo from '../views/User/expert/expertInfo.vue'
import UserManage from '../views/User/UserManage.vue'
import FrontPage from '../views/Home/Nav/HomeNav1FrontPage.vue'
import HomeGuide from '../views/Home/Nav/HomeNav5ExpertGuide.vue'
import guideDetail from '../views/Home/Detail/ExpertGuideDetail.vue'
import AllExpert from '../views/Home/Expert/AllExpert.vue'
import question from '../views/Home/Expert/ExpertQuestion.vue'
import appointment from '../views/Home/Expert/ExpertAppointment.vue'
import Financing from '../views/Home/Nav/HomeNav7Financing.vue'
import SmartMatch from '../views/Home/Nav/HomeNav7SmartMatch.vue'
import FinancingDetails from '../views/Home/Detail/FinancingDetails.vue'
import userGood from '../views/User/UserGoodsManager.vue'
import AboutUs from '../views/Home/AboutUs.vue'

// 使用 VueRouter 插件
Vue.use(VueRouter)

// 解决 ElementUI 导航栏中的 vue-router 在 3.0 版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 定义路由配置
// 定义路由配置
const routes = [
    {
        // 根路径，重定向到 /home
        path: '/',
        redirect: '/home'
    },
    {
        // 主页路由
        path: '/home',
        component: Home,
        children: [
            {
                // 子路径为空时，重定向到 front
                path: '',
                redirect: 'front'
            },
            {
                // 首页路由
                path: 'front',
                component: FrontPage
            },
            {
                // 商品列表页路由
                path: 'goods',
                component: HomeGoods
            },
            {
                // 求购需求页路由
                path: 'purchase',
                component: HomePurchase
            },
            {
                // 知识页路由
                path: 'knowledge',
                component: HomeKnowledge
            },
            {
                // 知识详情页路由，携带 id 参数
                path: 'knowledge/:id',
                component: KnowledgeDetail
            },
            {
                // 专家指南页路由
                path: 'guide',
                component: HomeGuide
            },
            {
                // 专家指南详情页路由，携带 id 参数
                path: 'guide/:id',
                component: guideDetail
            },
            {
                // 所有专家页路由
                path: 'allExpert',
                component: AllExpert
            },
            {
                // 专家问答页路由
                path: 'question',
                component: question
            },
            {
                // 专家预约页路由
                path: 'appointment',
                component: appointment
            },
            {
                // 购物车页路由
                path: 'shopcart',
                component: ShopCart
            },
            {
                // 融资页路由
                path: 'financing',
                component: Financing
            },
            {
                // 智能匹配页路由
                path: 'smartMatch',
                component: SmartMatch
            },
            {
                // 商品详情页路由
                path: 'details',
                component: Details,
            },
            {
                // 求购详情页路由
                path: 'purchaseDetails',
                component: purchaseDetails,
            },
            {
                // 融资详情页路由
                path: 'financingDetails',
                component: FinancingDetails,
            },
            {
                // 用户相关页面路由
                path: 'user',
                component: User,
                children: [
                    {
                        // 子路径为空时，重定向到 userinfo
                        path: '',
                        redirect: 'userinfo'
                    },
                    {
                        // 用户融资页路由
                        path: 'userfinance',
                        component: UserFinance
                    },
                    {
                        // 用户信息页路由
                        path: 'userinfo',
                        component: UserInfo
                    },
                    {
                        // 用户收货地址页路由
                        path: 'useraddress',
                        component: UserAddress
                    },
                    {
                        // 用户修改密码页路由
                        path: 'userpassword',
                        component: UserPassword
                    },
                    {
                        // 用户已发布商品页路由
                        path: 'publishedgoods',
                        component: PublishedGoods
                    },
                    {
                        // 管理员已发布需求页路由
                        path: 'publishedneedsAdmin',
                        component: PublishedNeedsAdmin
                    },
                    {
                        // 用户已发布知识页路由
                        path: 'publishedknowledges',
                        component: PublishedKnowledges
                    },
                    {
                        // 用户购买记录页路由
                        path: 'userbuy',
                        component: UserBuy
                    },
                    {
                        // 用户销售记录页路由
                        path: 'usersell',
                        component: UserSell
                    },
                    {
                        // 专家问答页路由（用户端）
                        path: 'expertQuestion',
                        component: expertQuestion
                    },
                    {
                        // 专家预约页路由（用户端）
                        path: 'expertAppoint',
                        component: expertAppoint
                    },
                    {
                        // 专家信息页路由（用户端）
                        path: 'expertInfo',
                        component: expertInfo
                    },
                    {
                        // 用户已发布需求页路由
                        path: 'publishedneeds',
                        component: PublishedNeeds
                    },
                ]
            },
            {
                // 用户商品管理页路由
                path: 'userGood',
                component: userGood,
                children: [
                    {
                        // 管理员已发布商品页路由
                        path: 'publishedgoodsAdmin',
                        component: PublishedGoodsAdmin
                    },
                    {
                        // 管理员已发布需求页路由
                        path: 'PublishedNeedsAdmin',
                        component: PublishedNeedsAdmin
                    }
                ]
            },
            {
                // 发布信息导航页路由
                path: 'addmessage',
                component: PublishNav,
                children: [
                    {
                        // 发布商品页路由
                        path: 'publishgoods',
                        component: PublishGoods
                    },
                    {
                        // 发布需求页路由
                        path: 'publishneeds',
                        component: PublishNeeds
                    },
                    {
                        // 发布知识页路由
                        path: 'publishknowledges',
                        component: PublishKnowledges
                    }
                ]
            },
            {
                // 关于我们页路由
                path: 'aboutUs',
                component: AboutUs
            },
            {
                // 用户管理页路由
                path: 'usermanage',
                component: UserManage
            }
        ]
    },
    {
        // 支付页路由
        path: '/payment',
        component: Payment
    },
    {
        // 登录页路由
        path: '/login',
        component: Login
    },
    {
        // 注册页路由
        path: '/register',
        component: Register
    }
]

const router = new VueRouter({
    routes,
    // 使用 hash 模式
    mode: 'hash',
})

export default router